package gunfire.relics;

import basemod.abstracts.CustomRelic;
import com.badlogic.gdx.graphics.Texture;
import com.megacrit.cardcrawl.actions.common.ApplyPowerAction;
import com.megacrit.cardcrawl.actions.common.RelicAboveCreatureAction;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.powers.DexterityPower;
import com.megacrit.cardcrawl.powers.StrengthPower;
import com.megacrit.cardcrawl.relics.AbstractRelic;
import gunfire.GunfireMod;
import gunfire.powers.ElementPower;
import gunfire.util.TextureLoader;

import static gunfire.GunfireMod.makeRelicOutlinePath;
import static gunfire.GunfireMod.makeRelicPath;

public class ExtravagantConsumption extends CustomRelic {

    public static final String ID = GunfireMod.makeID("ExtravagantConsumption");
    private static final Texture IMG = TextureLoader.getTexture(makeRelicPath("ExtravagantConsumption.png"));
    private static final Texture OUTLINE = TextureLoader.getTexture(makeRelicOutlinePath("blank.png"));

    public ExtravagantConsumption() {
        super(ID, IMG, OUTLINE, RelicTier.SHOP, LandingSound.CLINK);
        this.counter = 0;
    }

    @Override
    public void onEquip() {
        this.saveMoney();
    }

    @Override
    public void onGainGold() {
        this.saveMoney();
    }

    private void saveMoney(){
        if(AbstractDungeon.player.gold > 150){
            this.flash();
            this.addToBot(new RelicAboveCreatureAction(AbstractDungeon.player, this));
            int num = AbstractDungeon.player.gold - 150;
            AbstractDungeon.player.loseGold(num);
            this.counter += num;
        }
    }

    @Override
    public void atBattleStart() {
        int num = this.counter / 100;
        if(num > 0){
            this.addToBot(new ApplyPowerAction(AbstractDungeon.player, AbstractDungeon.player, new StrengthPower(AbstractDungeon.player, num), num));
            this.addToBot(new ApplyPowerAction(AbstractDungeon.player, AbstractDungeon.player, new DexterityPower(AbstractDungeon.player, num), num));
            this.addToBot(new ApplyPowerAction(AbstractDungeon.player, AbstractDungeon.player, new ElementPower(AbstractDungeon.player, num), num));
            this.flash();
            this.addToBot(new RelicAboveCreatureAction(AbstractDungeon.player, this));
        }
    }

    @Override
    public String getUpdatedDescription() {
        return DESCRIPTIONS[0];
    }

    @Override
    public AbstractRelic makeCopy() {
        return new ExtravagantConsumption();
    }
}
